package com.cyj.springbootservice.controller.jackson;

import com.cyj.springbootservice.api.entity.User;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @description:
 * @Author C_Y_J
 * @create 2021-03-05 15:57
 **/
@Controller
@RequestMapping(value = "/jackson")
public class JacksonController {

    @GetMapping(value = "/json1")
    @ResponseBody
    public String json() throws JsonProcessingException {
        User user = new User().setUserName("林青霞").setPassword("123456");
        return new ObjectMapper().writeValueAsString(user);
    }

    @GetMapping(value = "/json2")
    @ResponseBody
    public User test1() {
        User user = new User().setUserName("林青霞").setPassword("123456");
        return user;
    }
}